package com.zhentao.utils;

import lombok.Data;

@Data
public class ResultVo<T> {
    private Integer code;
    private String msg;
    private  T obj;

    public ResultVo() {}

    public ResultVo(int code, String msg, T obj) {
        this.code = code;
        this.msg = msg;
        this.obj = obj;

    }

    public ResultVo(ApiServiceExceptionEnum apiServiceExceptionEnum, T object) {
        this.code = apiServiceExceptionEnum.getCode();
        this.msg = apiServiceExceptionEnum.getMessage();
        this.obj = object;
    }
    public ResultVo(ApiServiceExceptionEnum apiServiceExceptionEnum) {
        this.code = apiServiceExceptionEnum.getCode();
        this.msg = apiServiceExceptionEnum.getMessage();
        this.obj = null;
    }

    public static ResultVo success(Object object) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(200);
        resultVO.setMsg("成功");
        resultVO.setObj(object);
        return resultVO;
    }

    public static ResultVo success() {
        return success(null);
    }
    public static ResultVo error(Integer code, String msg) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }
    public static ResultVo error(){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(400);
        resultVO.setMsg("失败");
        return resultVO;
    }
    public static ResultVo error(Integer code,String msg,Object obj){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(400);
        resultVO.setMsg(msg);
        resultVO.setObj(obj);
        return resultVO;
    }

    public static ResultVo error(ApiServiceExceptionEnum apiServiceExceptionEnum) {
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(apiServiceExceptionEnum.getCode());
        resultVO.setMsg(apiServiceExceptionEnum.getMessage());
        return resultVO;
    }
    public static ResultVo success(Integer code,String msg,Object obj){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setObj(obj);
        return resultVO;
    }

    public static ResultVo success(ApiServiceExceptionEnum apiServiceExceptionEnum) {
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(apiServiceExceptionEnum.getCode());
        resultVO.setMsg(apiServiceExceptionEnum.getMessage());
        return resultVO;
    }
    public static ResultVo success(ApiServiceExceptionEnum apiServiceExceptionEnum,Object object) {
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(apiServiceExceptionEnum.getCode());
        resultVO.setMsg(apiServiceExceptionEnum.getMessage());
        resultVO.setObj(object);
        return resultVO;
    }
}
